package com.amit;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestServlet  extends HttpServlet{
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		
		//1.collect the parameters
		String sn=request.getParameter("sname");
		String em=request.getParameter("email");
		
		String ems[]=request.getParameterValues("email");
		System.out.println(sn);
		System.out.println(em);
		
		for(String str:ems)
		{
			System.out.println(str);
		}
		
		//2.collect the Headers
		
		String ho=request.getHeader("host");
		String re=request.getHeader("refer");
		String al=request.getHeader("accepting-langauge");
		String ae=request.getHeader("accept-encoding");
		
		System.out.println(ho);
		System.out.println(re);
		System.out.println(al);
		System.out.println(ae);
	
	//3.collect cookies
		
		Cookie ck[]=request.getCookies();
		
		for(Cookie c:ck)
		{
			System.out.println(c.getName()+"..."+c.getValue());
		}
		
		Cookie ck1=new Cookie("email", "amit123@gmail.com");
		response.addCookie(ck1);
		
		Cookie ck2=new Cookie("phone","12344");
		response.addCookie(ck2);
		
		RequestDispatcher rd=request.getRequestDispatcher("show.jsp");
		rd.forward(request, response);
		

	}
	
	
	

}
